# 启动多个应用实例的PowerShell脚本

# 停止所有正在运行的Python进程
Write-Host "停止所有正在运行的Python进程..."
Get-Process -Name python -ErrorAction SilentlyContinue | Stop-Process -Force

# 等待进程停止
Start-Sleep -Seconds 2

# 启动多个应用实例
Write-Host "启动应用实例..."
$ports = 8001, 8002, 8003
foreach ($port in $ports) {
    Write-Host "启动应用实例在端口 $port..."
    Start-Process -FilePath "python" -ArgumentList "main.py", "--port", $port -WindowStyle Normal -WorkingDirectory "f:\bjhsp"
    # 等待实例启动
    Start-Sleep -Seconds 1
}

# 检查是否有Python进程运行
$pythonProcesses = Get-Process -Name python -ErrorAction SilentlyContinue
if ($pythonProcesses) {
    Write-Host "\n成功: 发现Python进程正在运行。"
} else {
    Write-Host "\n错误: 未找到运行中的Python进程。"
}

# 显示访问地址
Write-Host "\n应用实例地址:"
foreach ($port in $ports) {
    Write-Host "http://localhost:$port"
}

Write-Host "\n如果Nginx已配置，可通过 http://localhost 访问"
Write-Host "\n启动完成。按Enter键退出..."
Read-Host